﻿
@{
    ViewBag.Title = "CivilBriefView";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}

<div class="layui-card">
    <div class="layui-card-body">
        <p style="font-size:20px;">
            名称：@ViewBag.Name，单位：@ViewBag.Unit，税率：@ViewBag.TaxRate，单价：@ViewBag.UnitPrice
        </p>
        <p style="font-size:16px;">
            备注：@ViewBag.Memo
        </p>
    </div>
</div>
<table class="layui-table" id="demo" lay-filter="TableList"></table>

<script type="text/javascript">
    layui.use(['form', 'laydate', 'table', 'layer'], function ()
    {
        var form = layui.form;
        var table = layui.table;
        var TaxRate = "@ViewBag.TaxRate";
        var CivilPriceId =@ViewBag.CivilPriceId

            table.render({
                elem: '#demo'
                , method: 'post'
                //, height: 315
                , url: '/PreEstimate/CivilSingleTableRequest' //数据接口
                , page: true //开启分页
                , where: { SortName: "Id", Order: "asc", Condition: " and CivilPriceId=" + CivilPriceId }
                , limit: 100
                , limits: [100, 500, 1000]
                , cols: [[ //表头
                    { title: '序号', width: 50, rowspan: 2, align: 'center', type: 'numbers' }
                    , { field: 'XMMC', title: '项目名称', width: 180, rowspan: 2, align: 'center' }
                    , { field: 'GCLJSS', title: '工程计量算式', width: 200, rowspan: 2, align: 'center' }
                    , { field: 'DW', title: '单位', width: 80, rowspan: 2, align: 'center' }
                    , {
                        field: 'GCL', title: '工程量', width: 80, rowspan: 2, align: 'center',
                        templet: function (d)
                        {
                            return (d.GCL).toFixed(2);
                        }
                    }
                    , { title: '人工费', width: 200, colspan: 2, align: 'center' }
                    , { title: '材料费', width: 200, colspan: 2, align: 'center' }
                    , {
                        title: '总价', rowspan: 2, width: 120, align: 'center',
                        templet: function (d)
                        {
                            return (d.GCL * (d.RGDJ + d.CLDJ)).toFixed(2);
                        }
                    }
                    , { field: 'Memo', title: '备注', width: 200, rowspan: 2, align: 'center' }

                ], [
                    { field: 'RGDJ', title: '单价', width: 80, align: 'center' }
                    , {
                        title: '合价', width: 120, align: 'center',
                        templet: function (d)
                        {
                            return (d.GCL * d.RGDJ).toFixed(2);
                        }
                    }
                    , { field: 'CLDJ', title: '单价', width: 80, align: 'center' }
                    , {
                        title: '合价', width: 120, align: 'center',
                        templet: function (d)
                        {
                            return (d.GCL * d.CLDJ).toFixed(2);
                        }
                    }
                ]]
                , done: function (res, curr, count)
                {
                    //如果是异步请求数据方式，res即为你接口返回的信息。
                    //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                    //console.log(res);
                    var sum = 0;
                    var tax = 0;
                    for (var i = 0; i < res.data.length; i++) {
                        sum += res.data[i].GCL * (res.data[i].CLDJ + res.data[i].RGDJ);
                    }

                    tax = sum * TaxRate;
                    var temphtml = '';
                    temphtml = '<tr>' +
                        '<td align="center"></td>' +
                        '<td align="center">税金</td>' +
                        '<td align="center"></td>' +
                        '<td align="center">元</td>' +
                        '<td align="center">' + sum.toFixed(2) + '</td >' +
                        '<td align="center">' + (TaxRate * 100).toFixed(2) + '%</td>' +
                        '<td align="center"></td>' +
                        '<td align="center"></td>' +
                        '<td align="center"></td>' +
                        '<td align="center">' + tax.toFixed(2) + '</td>' +
                        '<td align="center"></td>' +
                        '<td align="center"></td>' +
                        '</tr>';
                    temphtml += '<tr style="background-color:#B0E0E6;">' +
                        '<td align="center" colspan="9">合计</td>' +
                        '<td align="center">' + (tax + sum).toFixed(2) + '</td>' +
                        '<td align="center" colspan="2"></td>' +
                        '</tr>';
                    $('tbody').append($(temphtml));
                }
            });


    });




</script>
